package ch.pizzapp.kurier;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.FragmentArg;
import org.androidannotations.annotations.UiThread;
import org.androidannotations.annotations.ViewById;

import android.support.v4.app.Fragment;
import android.widget.ImageView;
import android.widget.TextView;
import ch.pizzapp.kurier.data.NotificationData;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;

/**
 * Created by shanuka on 12/9/13.
 */
@EFragment(R.layout.notification_detail_activity)
public class NotificationDetailFragment extends Fragment {

	@ViewById(R.id.forum_title)
	TextView forumTitle;

	@ViewById(R.id.forum_date)
	TextView forumDate;

	@ViewById(R.id.imageView1)
	ImageView imageViewIcon;

	private DisplayImageOptions options;
	private ImageLoader imageLoader;
	@FragmentArg("NotificationData")
	NotificationData notificationData;

	@AfterViews
	void initAdapter() {
		options = new DisplayImageOptions.Builder()
				.showStubImage(R.drawable.white_background)
				.showImageForEmptyUri(R.drawable.white_background)
				.showImageOnFail(R.drawable.white_background)
				.cacheInMemory(true).cacheOnDisc(true)
				.displayer(new SimpleBitmapDisplayer()).build();
		imageLoader = ImageLoader.getInstance();
		bind(notificationData);

	}

	@UiThread
	public void bind(final NotificationData notificationData) {
		forumTitle.setText(notificationData.getMessage());
		forumDate.setText(notificationData.getDate());

		if (notificationData.getImage() != null) {

			imageLoader.displayImage(
					Constants.IMAGE_URL + notificationData.getImage(),
					imageViewIcon, options);
		}
	}

}